/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.components.panel.layouts;

import javax.swing.GroupLayout;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import org.balisunrise.builder.BuilderException;
import org.balisunrise.swing.components.panel.LayoutBuilder;

/**
 * Controí o layout para transações.
 *
 * @author Glauco
 */
public class TransactionLayoutBuilder implements LayoutBuilder{

    JPanel actionPanel;
    JPanel component ;

    public JPanel getActionPanel() {
        return actionPanel;
    }

    public void setActionPanel(JPanel actionPanel) {
        this.actionPanel = actionPanel;
    }

    public JPanel getComponent() {
        return component;
    }

    public void setComponent(JPanel component) {
        this.component = component;
    }

    /**
     * Controí o layout para transações.<br>
     * Deve haver dois componentes na lista, o primeiro deve ser a Representação
     * Visual (RV) do TransactionActions e o segundo deve ser a RV do Editor
     * ou do Search.
     * 
     * @param panel Painel da Transação.
     * @param components Lista de Componentes do painel.
     * @throws BuilderException
     */
    @Override
    public void buildLayout(JPanel panel) {

        panel.removeAll();
        GroupLayout layout = new GroupLayout(panel);
        panel.setLayout(layout);

        // HORIZONTAL
        GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup()
                .addComponent(actionPanel)
                //.addContainerGap()
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(component);

        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
            .addGroup(hGroup));

        // VERTICAL
        GroupLayout.ParallelGroup vGroup =
                layout.createParallelGroup(GroupLayout.Alignment.LEADING, true)
                .addComponent(actionPanel)
                .addComponent(component);

        layout.setVerticalGroup(layout.createSequentialGroup()
                .addGroup(vGroup));

    }

}
